package com.yuke.cloud.service.cmc.controller.frontend;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.api.pmc.dto.ProdSpecInfoDto;
import com.yuke.cloud.service.cmc.dto.CmsAppIds;
import com.yuke.cloud.service.cmc.dto.CmsAppTopicDataDetailDto;
import com.yuke.cloud.service.cmc.service.CmsAppTopicDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by wg on 2019/01/18.
*/
@Api(value = "WEB - CmsAppTopicDataController", tags = "处理CmsAppTopicData相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/mall/cms/app_topic_data")
public class MallCmsAppTopicDataController extends BaseController {
    @Resource
    private CmsAppTopicDataService cmsAppTopicDataService;


    @PostMapping("/app/topicIds")
    @ApiOperation(httpMethod = "POST", value = "分页获取所有记录")
    public Wrapper<PageInfo<CmsAppTopicDataDetailDto>> getAppListByTopicIds(@ApiParam(name = "cmsAppTopic", value = "根据主题名称查找") @RequestBody(required = false) CmsAppIds cmsAppIds,
                                                          @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                          @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<CmsAppTopicDataDetailDto> list = cmsAppTopicDataService.getAppListByTopicIds(cmsAppIds);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }

    /**
     * 获取主题下的商品
     * @param cmsAppTopicDataDetailDto
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/app/topicDataDetail")
    @ApiOperation(httpMethod = "POST", value = "获取所有记录")
    public Wrapper<PageInfo<ProdSpecInfoDto>> getAppDetailByTopicId(@ApiParam(name = "cmsAppTopic", value = "根据主题名称查找") @RequestBody CmsAppTopicDataDetailDto cmsAppTopicDataDetailDto,
                                                                   @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                   @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        System.out.println("获取AAAAAAAAAAAAAAAAAAAAA");

        PageHelper.startPage(page, size);
        List<ProdSpecInfoDto> list = cmsAppTopicDataService.getAppDetailByTopicId(cmsAppTopicDataDetailDto);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }

    /**
     * 获取主题及主题下的商品
     * @param cmsAppTopicDataDetailDto
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/app/topicsDataDetail")
    @ApiOperation(httpMethod = "POST", value = "获取所有记录")
    public Wrapper<List<CmsAppTopicDataDetailDto>> getAppDetailByTopicIds(@ApiParam(name = "cmsAppTopic", value = "根据主题名称查找") @RequestBody CmsAppTopicDataDetailDto cmsAppTopicDataDetailDto,
                                                                    @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                    @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        System.out.println("AAAAAAAAAAAAAAAAAAA");
        if (cmsAppTopicDataDetailDto!=null){
            if (cmsAppTopicDataDetailDto.getShopId()==null){
                cmsAppTopicDataDetailDto.setShopId(220854931912392704L);
            }
        }
        List<CmsAppTopicDataDetailDto> list = cmsAppTopicDataService.getAppDetailByTopicIds(cmsAppTopicDataDetailDto);

        return WrapMapper.ok(list);
    }
}
